package leetcode.editor.cn.structure;

/**
 * @author:
 * @since: 2023/11/6 18:34
 **/
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public ListNode getNext() {
        return next;
    }

    public void setNext(ListNode next) {
        this.next = next;
    }

    @Override
    public String toString() {
        ListNode head = this;
        StringBuilder sb = new StringBuilder();
        sb.append(val).append("->");
        return sb.toString();
    }

    public String toStringFull() {
        ListNode head = this;
        StringBuilder sb = new StringBuilder();
        while (head != null) {
            sb.append(head.val).append("->");
            if (head.next != null) {
                sb.append(head.next.val);
            } else {
                sb.append("null");
            }
            sb.append("  ");
            head = head.next;
        }
        return sb.toString();
    }

}